Skip to content

feat(alterschema): add format_type_mismatch rule#696

Open
Vaibhav701161 wants to merge 3 commits intosourcemeta:mainfrom
Vaibhav701161:feat/alterschema-format-type-mismatch-blaze
Open

feat(alterschema): add format_type_mismatch rule#696
Vaibhav701161 wants to merge 3 commits intosourcemeta:mainfrom
Vaibhav701161:feat/alterschema-format-type-mismatch-blaze

Conversation

@Vaibhav701161
Copy link
Copy Markdown

Summary

This PR introduces a new lint rule: format_type_mismatch to the AlterSchema module in Blaze.

The rule detects schemas where the format keyword is used alongside a non-string type.

{
  "type": "integer",
  "format": "email"
}

In JSON Schema, format validation is defined for string instances. Using it with other types does not have any effect and is typically an authoring mistake.

This rule highlights such cases to improve schema correctness and provide clearer diagnostics.

The rule emits a diagnostic when:

  • format exists
  • type exists
  • type is a single string value
  • type is not "string"

The diagnostic points to the format keyword location.

This rule is non auto-fixable because modifying either type or format would require assumptions about the author’s intent.


Implementation

The rule follows the existing AlterSchema linter architecture in Blaze:

  • implemented as a header-only rule in
    src/alterschema/linter/format_type_mismatch.h
  • registered in the AlterSchema linter bundle
  • integrated into the Blaze build configuration

The rule checks:

  • schema node is an object
  • format is defined and is a string
  • type is defined and is a string
  • type != "string"

If these conditions are met the rule returns:

APPLIES_TO_KEYWORDS("format")

Design Notes

This rule is designed to provide a more explicit diagnostic for misuse of the format keyword.

While similar cases may be implicitly handled by more generic rules (e.g., type-specific keyword validation), this rule focuses specifically on format to improve clarity and developer feedback.

The rule intentionally skips cases where type is an array (e.g., ["string", "integer"]), since format may still apply when the instance is a string.

The implementation aligns with existing Blaze conventions and does not introduce new abstractions or deviations from established patterns.


Tests

Tests were added following the existing AlterSchema testing patterns in Blaze.

The following scenarios are covered:

  • Rule fires when format is used with non-string types
  • Rule does not fire when type is "string"
  • Rule does not fire when format is missing
  • Rule does not fire when type is missing
  • Rule does not fire when type is an array including "string"
  • Rule fires inside nested subschemas (properties, items, etc.)
  • Rule correctly handles $ref scenarios where applicable

All tests are aligned with Blaze test structure and conventions.


Notes

  • This PR ports the rule from the previous implementation in the core repository, following the migration of the AlterSchema module to Blaze.
  • The implementation has been adapted to match Blaze-specific structure and conventions rather than copied directly.

- port rule from core to Blaze alterschema module
- align with Blaze architecture and conventions
- add full test coverage across supported scenarios

Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 9 files

- use walker metadata for keyword applicability
- target the format keyword location only
- decouple tests from unrelated trace ordering
- restore minimal CMake diff

Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
- revert rule logic to the original core condition
- restore keyword targeting and vocabulary guard
- remove Blaze-specific test helper indirection
- match core trace expectations in all dialect tests

Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 8 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="test/alterschema/alterschema_lint_draft3_test.cc">

<violation number="1" location="test/alterschema/alterschema_lint_draft3_test.cc:1097">
P2: The test assumes only two diagnostics under `/additionalProperties`, but the nested `properties` keyword is also eligible for `non_applicable_type_specific_keywords` and may produce a third trace.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant